package com.yupi.springbootinit.share.controller;


import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.yupi.springbootinit.share.utils.wallpaper.WallpaperData;
import com.yupi.springbootinit.share.utils.wallpaper.WallpaperEnum;
import com.yupi.springbootinit.share.utils.wallpaper.WallpaperResponseBodyResult;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


/**
 * 此接口为壁纸类的共享接口,调用的接口为咸虾米API平台
 * @url <a href="https://api.qingnian8.com/apis/wallpaper/homeBanner.html">...</a>
 * @version 1.0
 * @author xiaohu
 */
@RestController
@RequestMapping("/share/wallpaper")
public class WallpaperController {

    /**
     * 获取9张壁纸
     * @return WallpaperResponseBodyResult
     */
    @GetMapping("/random")
    public WallpaperResponseBodyResult randomWallpaper() {
        HashMap<String, Object> map = new HashMap<>();
        map.put(WallpaperEnum.HEADER_ACCESS_KEY.getKey(), WallpaperEnum.HEADER_ACCESS_KEY.getValue());
        WallpaperResponseBodyResult parse = JSONUtil.toBean(HttpUtil.get("https://tea.qingnian8.com/api/bizhi/randomWall", map), WallpaperResponseBodyResult.class);
        parse.setAuthor("");
        return parse;
    }

    /**
     * 搜索指定词条的壁纸
     *
     * @param keyword  词条
     * @param pageNum  页数
     * @param pageSize 个数
     * @return WallpaperResponseBodyResult
     */
    @PostMapping("/search")
    public WallpaperResponseBodyResult searchWallpaper(@RequestParam("keyword") String keyword,
                                                        @RequestParam("pageNum") Integer pageNum,
                                                        @RequestParam("pageSize") Integer pageSize) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("keyword", keyword);
        map.put("pageNum", pageNum);
        map.put("pageSize", pageSize);
        map.put(WallpaperEnum.HEADER_ACCESS_KEY.getKey(), WallpaperEnum.HEADER_ACCESS_KEY.getValue());
        WallpaperResponseBodyResult parse = JSONUtil.toBean(
                HttpUtil.get("https://tea.qingnian8.com/api/bizhi/searchWall", map),
                WallpaperResponseBodyResult.class);
        parse.setAuthor("");
        return parse;
    }
}
